package cn.com.huzo.repository.trade.impl;

import cn.com.huzo.model.entities.trade.ProductionInstructionLinesSuitSizeEntity;
import huzofw.repository.impl.GenericRepositoryImpl;
import huzofw.repository.impl.MyBatisDaoUtils;
import java.util.List;
import org.springframework.stereotype.Repository;
import cn.com.huzo.repository.trade.ProductionInstructionLinesSuitSizeRepository;
import java.util.HashMap;
import java.util.Map;

/**
 * 生产指示书明细-复合款尺码数据访问对象。
 *
 * @author 吴旭
 */
@Repository("ProductionInstructionLinesSuitSizeRepository")
public class ProductionInstructionLinesSuitSizeRepositoryImpl extends GenericRepositoryImpl<ProductionInstructionLinesSuitSizeEntity, String>
        implements ProductionInstructionLinesSuitSizeRepository {

    private final String namespace = "cn.com.huzo.repository.trade.ProductionInstructionLinesSuitSizeRepository";

    /**
     * 构造函数,设置the instance to ProductRepositoryImpl.class.
     */
    public ProductionInstructionLinesSuitSizeRepositoryImpl() {
        super(ProductionInstructionLinesSuitSizeEntity.class);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public String insert(ProductionInstructionLinesSuitSizeEntity instance) {
        getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insert"), instance);
        // 返回保存后的记录ID
        return instance.getLinesId();
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer insertForNewColourLines(Long headerId) {
        Map<String, Object> criterion = new HashMap<>();
        criterion.put("HeaderId", headerId);

        return getSqlSession().insert(MyBatisDaoUtils.getMapperQueryId(
                namespace, "insertForNewColourLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer updateParentLinesIdForNewColourLines(Long headerId) {
        Map<String, Object> criterion = new HashMap<>();
        criterion.put("HeaderId", headerId);

        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "updateParentLinesIdForNewColourLines"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<ProductionInstructionLinesSuitSizeEntity> fetchByParentLinesId(String linesId) {
        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchByParentLinesId"), linesId);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public List<Map<String, Object>> fetchProductSize(Long headerId, String styleNo, Long productId) {
        Map<String, Object> criterion = new HashMap();
        criterion.put("HeaderId", headerId);
        criterion.put("StyleNo", styleNo);
        criterion.put("ProductId", productId);

        return getSqlSession().selectList(MyBatisDaoUtils.getMapperQueryId(
                namespace, "fetchProductSize"), criterion);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer batchUpdate(List<ProductionInstructionLinesSuitSizeEntity> itemsList) {
        return getSqlSession().update(MyBatisDaoUtils.getMapperQueryId(
                namespace, "batchUpdate"), itemsList);
    }

    /**
     * {@inheritDoc}
     */
    @Override
    public Integer deleteByParentLinesId(String parentLinesId) {
        return getSqlSession().delete(MyBatisDaoUtils.getMapperQueryId(
                namespace, "deleteByParentLinesId"), parentLinesId);
    }
}
